#include "slLight.hh"

slLight::slLight()
{
   state = false;
   _light = -1;
}

slLight::~slLight()
{

}
	
void slLight::Init ( int light )
{
   _light = light;
   glEnable(_light);
   state = true;
}

void slLight::SetLight ( int light )
{
   if (_light != -1)
      glDisable(_light);
   _light = light;
   glEnable(_light);
   state = true;
}

void slLight::SetValues()
{

}

void slLight::TurnOn()
{
   if (_light != -1 && state == false)
   {
      glEnable(_light);
      state = true;
   }
}

void slLight::TurnOff()
{
   if (_light != -1 && state == true)
   {
      glDisable(_light);
      state = false;

   }
}

void slLight::Toggle()
{
   if (state == false)
      TurnOn();
   else
      TurnOff();
}

bool slLight::GetOnOffState()
{
   return state;
}

void slLight::SetAmbientColor(float r, float g, float b, float a)
{
   ambient[0] = r;
   ambient[1] = g;
   ambient[2] = b;
   ambient[3] = a;
}

void slLight::SetDiffuseColor (float r, float g, float b, float a)
{
   diffuse[0] = r;
   diffuse[1] = g;
   diffuse[2] = b;
   diffuse[3] = a;
}

void slLight::SetPosition(float x, float y, float z, float w)
{
   position[0] = x;
   position[1] = y;
   position[2] = z;
   position[3] = w;
}

void slLight::slLight::SetSpecular ( float r, float g, float b, float a )
{
   specular[0] = r;
   specular[1] = g;
   specular[2] = b;
   specular[3] = a;

   glMaterialfv(GL_FRONT, GL_SPECULAR, diffuse);
}

void slLight::SetSpotDirection ( float x, float y, float z )
{
   spot_direction[0] = x;
   spot_direction[1] = y;
   spot_direction[2] = z;

   glLightfv(_light, GL_SPOT_DIRECTION, spot_direction);
}

void slLight::SetSpotExponent ( float exponent )
{
   spot_exponent = exponent;
}

void slLight::SetSpotCutoff(float cutoff)
{
   spot_cutoff = cutoff;
   glLighti(_light, GL_SPOT_CUTOFF, spot_cutoff);
}

void slLight::SetConstantAtt(float constant)
{
   constant_attenuation = constant;
}

void slLight::SetLinearAtt(float linear)
{
      linear_attenuation = linear;
}

void slLight::SetQuadraticAtt(float quadratic)
{
   quadratic_attenuation = quadratic;
}

void slLight::draw()
{
   glLightfv(_light,GL_AMBIENT,ambient); 
   glLightfv(_light,GL_DIFFUSE,ambient); 
   glLightfv(_light, GL_POSITION, position);
}